<?php
/*
	插件概览
	分红插件主要显示哪些数据？
		1、基本数据
		分红订单总数 会员总数 分红商总数 
		分红订单近七天增长趋势折线图 会员数近七天增长折线图 分红商近七天增长折线图 
		收益总笔数/金额 结算总笔数/金额
		饼状图显示各状态收益数额  饼状图显示各状态结算总笔数/金额
		
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'welcome';
$tabs=array(
	array('op'=>'welcome','title'=>'概况'),
	array('op'=>'line','title'=>'趋势'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='welcome'){
	$this->model('model')->up_redfee();
	//会员
	$member=array(
		'member'=>$this->count('member',array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>0)),
		'agent'=>$this->count('member',array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>1)),
		'apply'=>$this->count('apply',array('uniacid'=>$_SESSION['uniacid'],'status'=>0)),
		'stop'=>$this->count('member',array('uniacid'=>$_SESSION['uniacid'],'stop'=>1)),
	);
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'会员概况','datas'=>array(
		array('title'=>'会员数量','num'=>1,'data'=>$member['member']),
		array('title'=>'分红商数量','num'=>1,'data'=>$member['agent']),
		array('title'=>'待审核分红商数量','num'=>1,'data'=>$member['apply']),
		array('title'=>'黑名单','num'=>1,'data'=>$member['stop']),
	));
	//收益
	$month_start=strtotime(date('Ym').'01');
	$commission_month['num']=$this->count('commission',array('type >'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$commission_month['money']=$this->sum('commission',array('type >'=>1,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$commission['num']=$this->count('commission',array('type >'=>1,'uniacid'=>$_SESSION['uniacid']));
	$commission['money']=$this->sum('commission',array('type >'=>1,'uniacid'=>$_SESSION['uniacid']),'money');
	//结算
	$fan_month['num']=$this->count('commission',array('type'=>6,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$fan_month['money']=$this->sum('commission',array('type'=>6,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$fan['num']=$this->count('commission',array('type'=>6,'uniacid'=>$_SESSION['uniacid']));
	$fan['money']=$this->sum('commission',array('type'=>6,'uniacid'=>$_SESSION['uniacid']),'money');
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'收益概况','datas'=>array(
		array('title'=>'收益笔数/金额','num'=>2,'data'=>array($commission['num'],$commission['money'])),
		array('title'=>'返额笔数/金额','num'=>2,'data'=>array($fan['num'],$fan['money'])),
		array('title'=>'本月收益笔数/金额','num'=>2,'data'=>array($commission_month['num'],$commission_month['money'])),
		array('title'=>'本月返额笔数/金额','num'=>2,'data'=>array($fan_month['num'],$fan_month['money'])),
	));
	
	$commission_pie=array(
		'title'=>'收益概况',
		'tablename'=>$this->tablename('commission'),
		'width'=>'50%',
		'field'=>'type',
		'field_options'=>$this->commission_money_types,
		'params'=>array('type >'=>1,'uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($commission_pie);
	$balance_pie=array(
		'title'=>'返额订单概况',
		'tablename'=>$this->tablename('commission'),
		'width'=>'50%',
		'field'=>'type',
		'field_options'=>array('6'=>'返额'),
		'params'=>array('type'=>6,'uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($balance_pie);
	set_html('title','分红概况');
	exi($return);
}
if($_RQ['op']=='line'){
	//趋势
	$order_params=array(
		'title'=>'近30天分红订单走势',
		'data'=>array(
			'tablename'=>$this->tablename('order'),
		),
	);
	$return['htmls'][]=model('core/echart')->line($order_params);
	$member_params=array(
		'title'=>'近三十天会员/分红商增长走势',
		'data'=>array(
			'会员增长'=>array(
				'tablename'=>$this->tablename('member'),
			),
			'分红商增长'=>array(
				'tablename'=>$this->tablename('member'),
				'params'=>array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>1),
				'time_field'=>'agenttime',
			)
		),
	);
	$return['htmls'][]=model('core/echart')->line($member_params);
	set_html('title','分红趋势');
	exi($return);
}